/***************************************************************
 * Name:      SetupCreatorMain.h
 * Purpose:   Defines Application Frame
 * Author:    Jeremie Fouche (jeremie.fouche@gmail.com)
 * Created:   2007-05-05
 * Copyright: Jeremie Fouche ()
 * License:
 **************************************************************/

#ifndef SETUPCREATORMAIN_H
#define SETUPCREATORMAIN_H

#include "scapp.h"
#include "gui.h"

#include "sc/context.h"

#include <set>
#include <map>


/**
* @class DlgAddChild
*/
class DlgAddChild : public DlgAddChildGui
{
public:
    DlgAddChild(wxWindow* parent = NULL) : DlgAddChildGui(parent) { }

protected:
	wxString m_sChild;

	typedef std::set<std::string> TListChild;
	TListChild m_lstChildName;

public:
	void AddChild(const std::string& sChild) { m_lstChildName.insert(sChild); }
	std::string GetChild(void) const { return m_sChild.c_str(); }

protected:
    virtual void OnInitDialog( wxInitDialogEvent& event );
    virtual void OnOK( wxCommandEvent& event );
};


/**
* @class SetupCreatorFrame
*/
class SetupCreatorFrame : public SCFrameGui
{
public:
    SetupCreatorFrame(wxWindow* parent);

protected:
    /**
    * @class ElementTID
    *
    * represent the tree item data
    */
    class ElementTID : public wxTreeItemData
    {
    public:
        ElementTID(sc::Setup::Element* pElement) : m_pElement(pElement) {}

    public:
        sc::Setup::Element* m_pElement;
    };

    /**
    * @class AttribCtrl
    *
    * Represent the attributes controls
    */
	class AttribCtrl
	{
	public:
		AttribCtrl(wxStaticText* pLabel, wxWindow* pControl, sc::Setup::Attribute& rAttribute)
		: m_pLabel(pLabel), m_pControl(pControl), m_rAttribute(rAttribute)
		{}

		wxStaticText*  m_pLabel;
		wxWindow*      m_pControl;

		sc::Setup::Attribute& m_rAttribute;
	};
	typedef std::map<std::string,AttribCtrl> TMapControls;

	typedef std::map<std::string,int> TMapIcons;

    /// Attributes
    sc::Context   m_context;
	TMapControls  m_controls;
	TMapIcons     m_mapIcons;

protected:
    /// Setup tree methods
    void Load(void);
    wxTreeItemId AddTreeChild(const wxTreeItemId& hParent, const sc::Setup::Element* pcElement);
    sc::Setup::Element* GetElement(const wxTreeItemId& tid) const;

    /// Attributes panel methods
    void RemoveAllControls(void);
	void SetControls(sc::Setup::Element& rElement);
    void SaveAttributes(void) const;

    /// Context methods
	int AddChild(sc::Setup::Element& rParent, const std::string& sChild, const wxTreeItemId& hParent);
	int DeleteElement(sc::Setup::Element* pElement, const wxTreeItemId& hElement);


    /// Virtual event handlers, from wxFB SCFrameGui class
    virtual void OnFileNew( wxCommandEvent& event );
    virtual void OnFileOpen( wxCommandEvent& event );
    virtual void OnFileSave( wxCommandEvent& event );
    virtual void OnFileExit( wxCommandEvent& event );
    virtual void OnEditAddChild( wxCommandEvent& event );
    virtual void OnUpdateEditAddChild( wxUpdateUIEvent& event );
    virtual void OnEditDeleteChild( wxCommandEvent& event );
    virtual void OnUpdateEditDeleteChild( wxUpdateUIEvent& event );
    virtual void OnTreeSetupContextMenu( wxTreeEvent& event );
    virtual void OnTreeSetupSelChanged( wxTreeEvent& event );
    virtual void OnTreeSetupSelChanging( wxTreeEvent& event );
    virtual void OnTreeSetupBeginLabelEdit( wxTreeEvent& event );
    virtual void OnTreeSetupEndLabelEdit( wxTreeEvent& event );

private:

    DECLARE_EVENT_TABLE()
};

#endif // SetupCreatorMAIN_H
